//
//  XRVideoPlayer.h
//  UniversallyFramework
//
//  Created by 鑫 李 on 2016/11/7.
//  Copyright © 2016年 CDITV. All rights reserved.
//
//  参照VIMVideoPlayer
//  通过接口将VideoPlayer的状态开放出来

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@class XRVideoPlayer;

@protocol XRVideoPlayerDelegate <NSObject>

@optional
- (void)videoPlayerIsReadyToPlayVideo:(XRVideoPlayer *)videoPlayer; // 播放就绪
- (void)videoPlayerDidReachEnd:(XRVideoPlayer *)videoPlayer; // 播放完成
- (void)videoPlayer:(XRVideoPlayer *)videoPlayer timeDidChange:(CMTime)cmTime; // 时间轴变化
- (void)videoPlayer:(XRVideoPlayer *)videoPlayer loadedTimeRangeDidChange:(float)duration; // 缓冲时间轴变化
- (void)videoPlayerPlaybackBufferEmpty:(XRVideoPlayer *)videoPlayer; // 播放>缓冲
- (void)videoPlayerPlaybackLikelyToKeepUp:(XRVideoPlayer *)videoPlayer; // 缓冲>播放
- (void)videoPlayer:(XRVideoPlayer *)videoPlayer didFailWithError:(NSError *)error; // 播放失败

- (void)videoPlayerShowLoadingIndicator:(XRVideoPlayer *)videoPlayer; // 显示loading界面
- (void)videoPlayerHideLoadingIndicator:(XRVideoPlayer *)videoPlayer; // 隐藏loading界面

@end

@interface XRVideoPlayer : NSObject

@property (nonatomic, weak) id<XRVideoPlayerDelegate> delegate;

@property (nonatomic, strong, readonly) AVPlayer *player;

@property (nonatomic, assign, getter=isPlaying, readonly) BOOL playing;
@property (nonatomic, assign, getter=isLooping) BOOL looping;
@property (nonatomic, assign, getter=isMuted) BOOL muted;

- (void)setURL:(NSURL *)url;
- (void)setPlayerItem:(AVPlayerItem *)playerItem;
- (void)setAsset:(AVAsset *)asset;

// Playback
- (void)play;
- (void)pause;
- (void)seekToTime:(float)time;
- (void)reset;

// AirPlay
- (void)enableAirPlay;
- (void)disableAirPlay;
- (BOOL)isAriplayEnabled;

// Time Updates
- (void)enableTimeUpdates;
- (void)disableTimeUpdates;

// Scrubbing
- (void)startScrubbing;
- (void)scrub:(float)time;
- (void)stopScrubbing;

// Volume
- (void)setVolume:(float)volume;
- (void)fadeInVolume;
- (void)fadeOutVolume;

@end
